package org.example.server.pop;

import com.alibaba.fastjson.JSON;
import org.example.po.PopCorpClientManagerDto;
import org.example.utils.MD5Util;
import org.example.utils.http.RedirectUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ToErp {



    /**
     * 订单拉取
     */
    public static void popToOrder(String phone, String password)  {
        PopCorpClientManagerDto popCorpClientManagerDto = ToPop.popLogin(phone, password);
        Map<String, Object> map = new HashMap<>();
        map.put("orgId", popCorpClientManagerDto.getOrgId());
        map.put("appId", popCorpClientManagerDto.getAppId());
        map.put("taskId", 50001);
        map.put("sign", MD5Util.encrypt(map, popCorpClientManagerDto.getAppSecret()));
        System.out.println(JSON.toJSONString(map));
        String s = RedirectUtil.doGetParam("https://h-api.ybm100.com/api/hackTask/pullDataInfo", map);

        System.out.println(s);
    }

    /**
     * 未开户订单拉取
     */
    public static void popToOrderCustomer(String orgId, String appId, String appSecret) {
        Map<String, Object> map = new HashMap<>();
        map.put("orgId", orgId);
        map.put("appId", appId);
        map.put("taskId", 140001);
        map.put("sign", MD5Util.encrypt(map, appSecret));
        System.out.println(JSON.toJSONString(map));
        String s = RedirectUtil.doGetParam("https://h-api.ybm100.com/api/hackTask/pullDataInfo", map);

        System.out.println(s);
    }

    /**
     * 客户信息拉取
     */

    public static void popClientInfo(String phone, String password) {
        PopCorpClientManagerDto popCorpClientManagerDto = ToPop.popLogin(phone, password);
        Map<String, Object> map = new HashMap<>();
        map.put("orgId", popCorpClientManagerDto.getOrgId());
        map.put("appId", popCorpClientManagerDto.getAppId());
        map.put("taskId", 120001);
        map.put("sign", MD5Util.encrypt(map,popCorpClientManagerDto.getAppSecret() ));
        System.out.println(JSON.toJSONString(map));
        String s = RedirectUtil.doGetParam("https://h-api.ybm100.com/api/hackTask/pullDataInfo", map);

        System.out.println(s);
    }

    /**
     * 数据筛选
     */
    public static void popDataFiltering(String phone, String password) {
        PopCorpClientManagerDto popCorpClientManagerDto = ToPop.popLogin(phone, password);
        Map<String, Object> map = new HashMap<>();
        map.put("orgId", popCorpClientManagerDto.getOrgId());
        map.put("appId", popCorpClientManagerDto.getAppId());
        map.put("taskId", 130001);
        map.put("sign", MD5Util.encrypt(map,popCorpClientManagerDto.getAppSecret() ));
        System.out.println(JSON.toJSONString(map));
        String s = RedirectUtil.doGetParam("https://h-api.ybm100.com/api/hackTask/queryTaskCondition", map);
        System.out.println(s);
        System.out.println(JSON.toJSONString(map));

    }

    /**
     * 111
     */
    public static String getCustomerCode(String orgId, String appId, String appSecret) {
        Map<String, Object> map = new HashMap<>();
        map.put("orgId", orgId);
        map.put("appId", appId);
        map.put("taskId", 140001);
        map.put("sign", MD5Util.encrypt(map, appSecret));
        String s = RedirectUtil.doGetParam("https://h-api.ybm100.com/api/hackTask/pullDataInfo", map);
        System.out.println(s);
        System.out.println(JSON.toJSONString(map));
        return s;
    }

    /**
     * 心跳检测
     */
    public static void client(String orgId, String appId, String appSecret) {
        Map<String, Object> map = new HashMap<>();
        map.put("orgId", orgId);
        map.put("appId", appId);
        map.put("jsonData", "");
        map.put("version", "3.4");
        String encrypt = MD5Util.encrypt(map, appSecret);
        System.out.println(encrypt);
        Map<String, String> objectMap = new HashMap<>();
        objectMap.put("orgId", orgId);
        objectMap.put("appId", appId);
        objectMap.put("jsonData", "");
        objectMap.put("version", "3.4");
        objectMap.put("sign", encrypt);
        System.out.println(objectMap);
        String s = RedirectUtil.doPostByFrom("https://h-api.ybm100.com/api/hackTask/pushClientInfo", objectMap);
        System.out.println(s);


    }

    /**
     * 客户变更
     */
    public static void popChangeInfo(String orgId, String appId, String appSecret) {
        Map<String, Object> map = new HashMap<>();
        map.put("orgId", orgId);
        map.put("appId", appId);
        map.put("taskId", 190001);
        map.put("sign", MD5Util.encrypt(map, appSecret));
        System.out.println(JSON.toJSONString(map));
        String s = RedirectUtil.doGetParam("https://h-api.ybm100.com/api/hackTask/pullDataInfo", map);
        System.out.println(s);
    }

    /**
     * 客户变更
     */
    public static void CustomerPullTask(String orgId, String appId, String appSecret) {

        List<Map<String, Object>> list = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        map.put("id", 1212323);
        map.put("result", 1212323);
        map.put("orgId", orgId);
        map.put("no", 1212323);
        list.add(map);
        Map<String, Object> map1 = new HashMap<>();
        map.put("orgId", orgId);
        map.put("appId", appId);
        map.put("jsonData", JSON.toJSONString(list));
        map.put("sign", MD5Util.encrypt(map, appSecret));
        System.out.println(JSON.toJSONString(map));
        String s = RedirectUtil.doGetParam("https://h-api.ybm100.com/api/hackTask/callbackForCustomerPullTask", map);
        System.out.println(s);
    }


}
